package playground.twitterSite;

import java.util.List;

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.api.TimelineMethods;
import twitter4j.conf.ConfigurationBuilder;

public class MyTwitter {
	private Twitter tweeterAcc = null;
	private String 	consumerKey;
	private String 	consumerSecret;
	private String 	accesToken;
	private String 	accesTokenSecret;
	private boolean inizializedCredentials;
	private Twitter twitter;
	private boolean configuredAcc;
	
	
	
	public MyTwitter(){
	}
	
	public void inicializeCredentials(){
		//TODO: inicializar los atributos!
		this.consumerKey  = /**/; 
		this.consumerSecret = /**/;
		this.accesToken = /**/;
		this.accesTokenSecret  = /**/;
		this.inizializedCredentials 	= true;
	}
	
	public void configureAcc(){
		inicializeCredentials();
		ConfigurationBuilder cb = new ConfigurationBuilder();
		cb.setDebugEnabled(true)
		  .setOAuthConsumerKey(this.consumerKey)
		  .setOAuthConsumerSecret(this.consumerSecret )
		  .setOAuthAccessToken(this.accesToken)
		  .setOAuthAccessTokenSecret(this.accesTokenSecret);
		TwitterFactory tf = new TwitterFactory(cb.build());
		this.twitter = tf.getInstance();
		this.configuredAcc = true;
	}
	
	public void tweet(String msg){
		if ( ! this.configuredAcc ){
			this.configureAcc();
		}
		Status status;
		try {
			status = this.twitter.updateStatus(msg);
			System.out.println("Successfully updated the status to [" + status.getText() + "].");
		} catch (TwitterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    
	}

	public static void main (String[] args) throws TwitterException
	{
		MyTwitter tw = new MyTwitter(); 
		tw.tweet("Good moorning Vietnam! from #twitter4j");
	    
	    
	}
	
}
